package cn.web.management.service.general;

import cn.web.management.dao.impl.UpdateUserDaoImpl;
import cn.web.management.dao.inface.UpdateUserDao;
import cn.web.management.domain.PersonalInform;
import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

public class EditPersonalInform {

    /**
     * @description: 用户修改个人信息，合并数据库中信息后，再存回数据库
     * @paramName: [employno, pNew]
     * @paramType: [java.util.Map<java.lang.String,java.lang.Object>, cn.web.management.domain.PersonalInform]
     * @returnType: boolean
     */
    public boolean editInform(Map<String, Object> employno, PersonalInform pNew){
        PersonalInform p = new PersonalInform();
        try {
            BeanUtils.populate(p, employno);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
//        ('null', 'null', 'null', 'null', 'null', 'null', '涂睿星', '男', '1989-2-1',
//        'null', '汉族', '中共预备党员', '正常', 0, '54233719560126531', '13151795179',
//        '华中科技大学-法学', '学士', '梦联动', '会计助理', 'null')
        pNew.setEmployno(p.getEmployno());
        pNew.setGroupno(p.getGroupno());
        pNew.setUsername(p.getUsername());
        pNew.setUserpassword(p.getUserpassword());
        pNew.setIdentity(p.getIdentity());
        pNew.setUserPortrait(p.getUserPortrait());
        pNew.setEmployment_time(p.getEmployment_time());

        UpdateUserDao updateUserDao = new UpdateUserDaoImpl();
        boolean addInform = updateUserDao.updateInform(pNew);
        if (addInform)
            return true;
        return false;
    }
}
